package sample.common;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;
 public class ViewUtil {
    private static Stage stage = new Stage();
    static ProgressIndicator progressIndicator = null;


    {
//        stage.setResizable(false);
        stage.setWidth(200);
        stage.setHeight(100);
//        stage.initStyle(StageStyle.DECORATED);
    }

    public static void delayStage(double n) {
//        FXMLLoader fxmlLoader = new FXMLLoader();
//        fxmlLoader.setLocation(ViewUtil.class.getResource("/fxml/delayView.fxml"));
//        AnchorPane root = null;
//        try {
//
//            fxmlLoader.load();
//            root = fxmlLoader.getRoot();
//            progressIndicator = (ProgressIndicator)root.getChildren().get(0);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        AnchorPane root = new AnchorPane();
        root.getChildren().addAll(progressIndicator);
        Scene scene = new Scene(root);
        stage.setAlwaysOnTop(true);
        stage.setScene(scene);
        stage.show();
        for (double i = 0; i <= n; i++) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(i / 10);
            progressIndicator.setProgress((i / n));

        }
//        stage.showAndWait();
//        ViewUtil.closeDelayStage();
//  }
    }

    public static void showDelayStage(){
//        stage.setTitle("正在载入数据......");

//        stage.setAlwaysOnTop(true);
    }
    public static void closeDelayStage() {
        stage.close();
    }


}


